/**
 * @author        hejiyang <silentmanager@163.com>
 * @date          2024-11-11 23:04:27
 * Copyright © YourCompanyName All rights reserved
 */

import request from '@/config/axios'
import { ApiResponse } from '@/types/ref'
import { TableDataModel } from '@/views/order/creation/index.vue'

// 创建时查看是否锁单
export const lockStatus = async (mobile: string) => {
  return await request.request<ApiResponse<boolean>>({
    url: `/crm/customer/lockStatus?mobile=${mobile}`
  })
}

export interface CreateOrderInfoReq {
  id: number
  packageInfo: TableDataModel[]
  customerId: number
  customerPhone: string
  customerName: string
  address: string
  customerType: string
  gender: string
  age: number
  department: number
  teamId: number
  contactId: number
  deliveryMethod: number
  contactOnDelivery: boolean
  orderNote: string
  packagePrepayment: number
  orderStatus: string
  logisticStatus: number
  createTime: string
}

// 创建订单信息
export const createOrderInfo = async (data: CreateOrderInfoReq) => {
  return await request.request<ApiResponse<boolean>>({
    url: `/bms/order-info/create`,
    data,
    method: 'POST'
  })
}

export interface queryByPhoneRes {
  id: string
  name: string
  sex: string
  age: number
  lockStatus: boolean //锁定状态
  mobile: string //电话
  detailAddress: string //详细地址
  level: string //客户类型
}
// 根据手机号查询客户
export const queryByPhone = async (params) => {
  return await request.get<queryByPhoneRes>({ url: `/crm/customer/query-by-phone`, params })
}

export interface SimpleListUserRes {
  deptId: number
  deptName: string
  id: number
  nickname: string
}
// 对接人员选择
export const simpleListUser = async (params: { deptId: string }) => {
  return await request.get<SimpleListUserRes[]>({ url: `/system/user/contact-simple-list`, params })
}

// 对接人员选择（不含被禁用账号）
export const contactSimpleAllListUser  = async (params: { deptId: string }) => {
  return await request.get<SimpleListUserRes[]>({ url: `/system/user/contact-simple-all-list`, params })
}

// 订单喜讯
export const simpleOrderList = async () => {
  return await request.get<string[]>({
    url: `/crm/statistics/simple-order-list`
  })
}
